//线段树-剪枝(取模操作)

#include <iostream>
using namespace std;
const int N = 1e5 + 10;
#define lc p << 1
#define rc p << 1 | 1
typedef long long ll;
ll a[N];

struct node
{
    int l, r;
    ll sum, max;
}tr[N << 2];

void pushup(int p)
{
    tr[p].sum = tr[lc].sum + tr[rc].sum;
    tr[p].max = max(tr[lc].max, tr[rc].max);
}

void build(int p, int l, int r)
{
    tr[p] = {l, r, a[l], a[l]};
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(lc, l, mid); build(rc, mid + 1, r);
    pushup(p);
}

//单点修改
void modify1(int p, int x, int k)
{
    int l = tr[p].l, r = tr[p].r;
    if(x == l && r == x) 
    {
        tr[p].sum = tr[p].max = k;
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) modify1(lc, x, k);
    else modify1(rc, x, k);
    pushup(p);
}

//区间修改
void modify2(int p, int x, int y, int mod)
{
    if(tr[p].max < mod) return;//剪枝
    int l = tr[p].l, r = tr[p].r;
    if(l == r)
    {
        tr[p].sum = tr[p].sum % mod;
        tr[p].max = tr[p].max % mod;
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) modify2(lc, x, y, mod);
    if(y > mid) modify2(rc, x, y, mod);
    pushup(p);
}

//区间查询
ll query(int p, int x, int y)
{
    int l = tr[p].l, r = tr[p].r;
    if(x <= l && r <= y) return tr[p].sum;
    int mid = (l + r) >> 1;
    ll sum = 0;
    if(x <= mid) sum += query(lc, x, y); 
    if(y > mid) sum += query(rc, x, y);
    return sum;
}

int main()
{
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    build(1, 1, n);
    while(m--)
    {
        int op, l, r, x, k; cin >> op;
        if(op == 1)
        {
            cin >> l >> r;
            cout << query(1, l, r) << endl;
        }
        else if(op == 2)
        {
            cin >> l >> r >> x;
            modify2(1, l, r, x);
        }
        else
        {
            cin >> k >> x;
            modify1(1, k, x);
        }
    }    
    return 0;
}